import java.util.Scanner;

public class test {
    //得到一个数字的每一位，并实现其每一位相加
    public static int sum(int n){
        if(n < 10){
            return n;
        }else{
            return sum(n  / 10) + (n % 10);
        }
    }
    public static void main(String[] args) {
        System.out.println(sum(123));
    }
    //得到一个数字的每一位
    public static void print(int n){
        if (n<10){
            System.out.println(n);
        }else {
            print(n / 10);
            System.out.println(n % 10);
        }
    }
    public static void main3(String[] args) {
        print(123);
    }
    //迭代法求斐波那契数列第N项
    public static int fib2(int n){
        if(n == 1||n == 2){
            return 1;
        }
        int f1 = 1;
        int f2 = 1;
        int f3 = -1;
        for(int i = 3;i <= n;i++){
            f3 = f1 + f2;
            f1 = f2;
            f2 = f3;
        }
        return f3;
    }
    public static void main2(String[] args) {
        Scanner sc = new Scanner(System.in);
        System.out.print("请输入你要查询第几项:");
        int m = sc.nextInt();
        System.out.println(fib2(m));
    }
    //递归法求斐波那契数列第N项
    public  static int fib(int n){
        if(n == 1||n == 2){
            return 1;
        }else {
            return fib(n - 1)+fib(n - 2);
        }
    }
    public static void main1(String[] args) {
        Scanner sc = new Scanner(System.in);
        System.out.print("请输入你要查询的是第几项:");
        int i = sc.nextInt();
        System.out.println(fib(i));
    }
}
